def isParamsInProjectName = currentBuild.projectName.endsWith(")")
def nodeName = isParamsInProjectName ? currentBuild.projectName.find(/\(([^\)]+)\)/, {group -> group[1]}) : params.NODE_NAME
def projectName = currentBuild.projectName.split('\\(')[0]
if (params.ENV != null) {
    projectName = projectName.replace("mdm", "mdm-${params.ENV}")
}
def buildProjectName = isParamsInProjectName ? "mdm-angular-client-build(159test)" : "mdm-angular-client-build"

def allEnvProps = [
    'mdm-pilotrun-console-website': [
        buildProjectName: buildProjectName,
        appDir: '/data/apps/mdm_client',
        artifactName: 'mdm_pilotrun_client.zip',
    ],
    'mdm-product-console-website': [
        buildProjectName: buildProjectName,
        appDir: '/data/apps/mdm_client',
        artifactName: 'mdm_product_client.zip',
    ],
    'mdm-test-console-website': [
        buildProjectName: buildProjectName,
        appDir: '/data/apps/mdm_client',
        artifactName: 'mdm_test_client.zip',
    ]
]

def envProp = allEnvProps[projectName]

if (params.AGENT_USER_NAME == null) {
    envProp.agentUserName = "xkwx";
} else {
    envProp.agentUserName = params.AGENT_USER_NAME;
}

node(nodeName) {
//    checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'jcyy_svn_credential', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'http://114.55.64.147/svn/mdm/trunk/jenkins/deploy-scripts']], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']])
    checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://gitee.com/bjwangwei/gitee-test.git']]])
    def deploy = load 'jenkins/deploy-scripts/consoleWebSiteDeploy.groovy'
    deploy.deploy(envProp)
}